﻿@model Fap.AspNetCore.ViewModel.JqGridViewModel
@{
    //在岗状态
    IEnumerable<Fap.Core.Infrastructure.Metadata.FapDict> empStatus = ViewBag.EmpStatus;
}
<title><fap-multilang lang-key="empinfo_index_title" default-content="员工档案"></fap-multilang>    </title>

<link href="~/Content/css/bootstrap-timeline.css" rel="stylesheet" />

<style>
    .billskin .layui-layer-btn0 {
        background-color: #d15b47 !important;
        border-color: #428bca;
    }
</style>
<div class="row">
    <div class="col-xs-12">
        <div id="widget-box-orgdept" class="widget-box">
            <div class="widget-header widget-header-flat">
                <h4 class="widget-title">
                    <fap-multilang lang-key="empinfo_index_title" default-content="员工档案"></fap-multilang>
                </h4>
                <div class="widget-toolbar">
                    <a href="#" data-action="fullscreen" class="orange2">
                        <i class="ace-icon fa fa-expand"></i>
                    </a>
                </div>
                <div class="widget-toolbar">
                    <label>
                        <input name="chkshowpartjob" id="chkshowpartjob" type="checkbox" class="ace" />
                        <span class="lbl"> 兼职</span>
                    </label>
                    <label>
                        <input type="checkbox" id="chkphoto" class="ace" />
                        <span class="lbl">
                            <fap-multilang lang-key="mss_employees_page_photo" default-content="照片"></fap-multilang>
                        </span>
                    </label>
                </div>

                <div class="widget-toolbar">
                    <fap-button id="btnSchedule" btn-tag="link" content="排班" icon-before="fa fa-calendar-check-o blue" class-name="info"></fap-button>
                    <fap-button id="btnSubInfo" btn-tag="link" content="附属信息" icon-before="fa fa-paperclip blue" class-name="info"></fap-button>
                    <fap-button id="btnEmployeeHistory" btn-tag="link" content="历史" icon-before="fa fa-history blue" class-name="info"></fap-button>
                </div>
                <div class="widget-toolbar">
                    <fap-button id="btnTmCardRecord" btn-tag="link" content="考勤打卡" icon-before="fa fa-credit-card blue" class-name="info"></fap-button>
                    <fap-button id="btnEmpReport" btn-tag="link" content="日报周报" icon-before="fa fa-calendar-check-o blue" class-name="info"></fap-button>
                </div>
            </div>
            <div class="widget-body">
                <!-- #section:custom/widget-box.toolbox -->
                <div class="widget-main">
                    <fap-grid id="employee" grid-model="Model" 
                              auto-width="true" on-select-row="ShowPhoto(rowid)" multi-box-only="true" multi-select="true"  register-authority="false" shrink-fit="false"></fap-grid>
                </div>
            </div>
        </div>
        <!-- /section:elements.tab -->
        <div id="right-menu" class="modal aside" data-body-scroll="false" data-offset="true" data-placement="right" data-fixed="true" data-backdrop="invisible" tabindex="-1">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header no-padding">
                        <div class="table-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                <span class="white">&times;</span>
                            </button>
                            <fap-multilang lang-key="department" default-content="部门"></fap-multilang>
                        </div>
                    </div>

                    <div class="modal-body">
                        <div id="treeDeptDiv" class="widget-main ">                          
                            <div>
                                <span><fap-multilang lang-key="employee_status" default-content="在岗状态"></fap-multilang>: &nbsp;</span>
                                <div>
                                    @foreach (var item in empStatus)
                                    {
                                        bool chk = item.Code == "Current";
                                        <label>
                                            <input data-ctrl="empstatus" name="form-field-checkbox-empstatus" value="@item.Code" type="checkbox" fap-checked="chk" class="ace" />
                                            <span class="lbl"> @item.Name</span>
                                        </label>
                                    }
                                </div>
                            </div>
                            <div class="scrollable">
                                <fap-tree id="orgdept" is-async="true" get-url="/SelfService/Api/DominationDepartment"></fap-tree>
                            </div>
                        </div>
                    </div>
                </div><!-- /.modal-content -->

                <button class="aside-trigger btn btn-purple btn-app btn-xs ace-settings-btn" data-target="#right-menu" data-toggle="modal" type="button">
                    <i data-icon1="fa-sitemap" data-icon2="fa-minus" class="ace-icon fa fa-sitemap bigger-110 icon-only"></i>
                </button>
            </div><!-- /.modal-dialog -->
        </div>

    </div>
</div>

<script> 
    var scripts = [null, "/Content/js/jquery-migrate-1.1.0.js", "/Content/js/jquery.jqprint-0.3.js", "/Scripts/Employee/EmpIndex.js?v=1",  null];
    $('.page-content-area').ace_ajax('loadScripts', scripts, function () {
        jQuery(function ($) {
            $('.modal.aside').ace_aside();
            $(document).one('ajaxloadstart.page', function (e) {
                $('#tree-orgdept').jstree("destroy");
                $('.modal.aside').remove();
                $(window).off('.aside');
            })         
            //排班
            $("#btnSchedule").on(ace.click_event, function () {
                var ret = getSelectedRow("grid-employee");
                if (ret == null) {
                    return;
                }
                bootboxWindow($.lang("time_schedule","排班"),basePath+"/Time/Manage/ScheduleInfo/"+ret.Fid)
            });            

            $("#btnSubInfo").on(ace.click_event, function () {
                var rowData = getSelectedRow("grid-employee");
                if (rowData === null) {
                    return;
                }               
                var dialog = bootbox.dialog({
                    title: $.lang("appertain_info", "附属信息"),
                    size: 'large',
                    message: '<p><i class="fa fa-spin fa-spinner"></i> Loading...</p>',
                    buttons: {
                        cancel: {
                            label: "关闭", className: "btn-default"
                        }
                    }
                });
                var data = { "gridViews": @Html.Raw(ViewBag.SubInfo)};
                $.each(data.gridViews, function (i, v) {
                    v.defaultValues.push({ "Field": "EmpUid", "Value": rowData.Fid });
                    v.defaultValues.push({ "Field": "EmpUidMC", "Value": rowData.EmpName });
                    v.defaultValues.push({ "Field": "EmpCode", "Value": rowData.EmpCode });
                });
                dialog.init(function () {
                    var url = "@Html.Raw(Url.Action("MultiDataGrid", "Component", new { area = "" }))";
                    $.post(url, data, function (ev) {
                        dialog.find('.bootbox-body').html(ev);
                    })
                });
            });
            //历史修改信息
            $("#btnEmployeeHistory").on(ace.click_event, function () {
                var rowData = getSelectedRow("grid-employee");
                if (rowData === null) {
                    return;
                }
                if (rowData.IsMainJob == 0) {
                    $.msg("此条信息为兼职信息，请选择主职信息查看！");
                    return;
                }
                bootboxWindow($.lang("employee_history", "历史追溯"),
                    basePath + "/Component/DataHistory", null, { bn: 'Employee', fid: rowData.Fid });               

            });
            $("#btnEmpReport").on(ace.click_event, function () {
                var rowData = getSelectedRow("grid-employee");
                if (rowData === null) {
                    return;
                }
                bootboxWindow($.lang("day_report", "日报周报"),
                    basePath + "/SelfService/Mss/EmpReport", null, { empUid: rowData.Fid });          
            })
            $("#btnTmCardRecord").on(ace.click_event, function () {
                var rowData = getSelectedRow("grid-employee");
                if (rowData === null) {
                    return;
                }
                bootboxWindow($.lang("time_card_record", "考勤打卡"),
                    basePath + "/Time/Manage/EmpCardRecord", null, { empUid: rowData.Fid });
            })
            //部门变化事件，加载人员信息
            $('#tree-orgdept').on("changed.jstree", function (e, data) {
                if (data && data.selected && data.selected.length) {
                    var deptid = data.selected[0];
                    //获取所有子Fid
                    var childs = data.node.children_d;
                    var selids = childs.concat(deptid);
                    //筛选有权限的节点
                    var treeDept = $('#tree-orgdept').jstree(true);
                    var sels = $.grep(selids, function (d, i) {                        
                        return treeDept.get_node(d).data.isDept === 1;

                    });
                    var filter = { "groupOp": "AND" };
                    var rules = [];
                    rules.push({ "field": "DeptUid", "op": "in", "data": sels.join(',') });                    
                    //在岗状态
                    var selEmpStatus = [];
                    $("input[data-ctrl=empstatus]").each(function () {
                        if ($(this).is(':checked')) {
                            selEmpStatus.push($(this).val());
                        }
                    })
                    if (selEmpStatus != '')
                    {
                        rules.push({ "field": "EmpStatus", "op": "in", "data": selEmpStatus.join(',') });
                    }
                    //兼职
                    if ($('#chkshowpartjob').get(0).checked) {
                        //兼职打勾的话，去掉职位类型条件
                    } else {
                        //默认显示主职
                        rules.push({ "field": "IsMainJob", "op": "eq", "data": 1 });
                    }
                    filter.rules = rules;
                    reloadGrid("grid-employee", { filters: JSON.stringify(filter) });

                }
            });

        })
    });
</script>